unit SmallStruct.Resource.TSSResourceRegisterTable;

interface

uses Types,
  Classes,
  SmallStruct.Core.TSSObjectFactory,
  SmallStruct.Resource;

type
  TSSResourceRegisterTable = class(TSSObjectFactory, ISSResourceRegisterTable)
  private
    _ResourceRegisterTable: TStringList;
  private
    function QueryResource(AObjectName: string; var ASourceNameArray: TStringDynArray): Boolean;
  public
    procedure InitObject; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

implementation

uses SmallStruct.Core,
  SmallStruct.Tools,
  SmallStruct.BusinessObject;

{ TSSResourceRegisterTable }

constructor TSSResourceRegisterTable.Create(AOwner: TComponent);
begin
  inherited;

  _ResourceRegisterTable := TStringList.Create;
end;

destructor TSSResourceRegisterTable.Destroy;
begin
  _ResourceRegisterTable.Free;

  inherited;
end;

procedure TSSResourceRegisterTable.InitObject;
var
  ResourceRegisterTableLoader: ISSResourceRegisterTableLoader;
begin
  inherited;

  ResourceRegisterTableLoader := ((GetSystemObject.GetGlobalObjectTable as ISSObjectContainer).GetObject(SS_BUSINESS_OBJECT_FACTORY_NAME) as ISSBusinessObjectFactory).GetBusinessObject(SS_RESOURCE_REGISTER_TABLE_LOADER_NAME) as ISSResourceRegisterTableLoader;
  try
    ResourceRegisterTableLoader.LoadResourceRegisterTable(_ResourceRegisterTable);
  finally
    ResourceRegisterTableLoader.ReleaseObjectInstance;
  end;
end;

function TSSResourceRegisterTable.QueryResource(AObjectName: string; var ASourceNameArray: TStringDynArray): Boolean;
begin
  if _ResourceRegisterTable.IndexOfName(AObjectName) >= 0 then
  begin
    Result := True;
    ASourceNameArray := TSSString.SplitStringToArray(_ResourceRegisterTable.Values[AObjectName], ',');
  end
  else
    Result := False;
end;

end.
